<script>
import * as api from '@/api/customer/tag'
import AddTag from '@/components/AddTag'

export default {
  name: 'GroupTag',
  components: { AddTag },
  props: {
    // "标签分组类型(1:客户标签;2:群标签)"
    type: {
      type: String,
      default: '1',
    },
  },
  data() {
    return {
      fits: ['fill', 'contain', 'cover', 'none', 'scale-down'],
        url: 'http://124.221.200.247:9000/test/fed702d3-163c-45f8-9210-2b9e2f4d8d35/7474a64b-38a6-46cd-9364-5acb7065e137.png',
      testUrl: "https://i0.hdslb.com/bfs/archive/f772b769267f602314f629a64dd191ceb43d95ef.jpg",
      query: {
        pageNum: 1,
        pageSize: 10,
        groupName: '',
        groupTagType: this.type,
        status: ''
      },
      // 0-审核中 1-被封禁 2-正常
      dictCustomerType: Object.freeze({ 0: '审核中', 1: '被封禁', 2: '正常' }),
      forbidForm: {
        id: '',
        beComplainGroupId: '',
        status: '',
        reason: '',
        expireTime: ''
      },
      // 遮罩层
      loading: false,
      dialogVisible: false,
      // 表单参数
      form: {
        groupName: '',
        weTags: [],
      },
      // 添加标签输入框
      newInput: '',
      // 添加标签显隐
      newInputVisible: false,
      // 表单验证规则
      rules: Object.freeze({
        groupName: [{ required: true, message: '必填项', trigger: 'blur' }],
      }),
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      lastSyncTime: 0,
    }
  },
  computed: {},
  created() {
    // this.query.groupTagType = this.type
    this.getList()
  },
  methods: {
    resetQuery() {
      this.query.groupName = ''
      this.query.status = ''
      this.getList(1)
    },
    getList(page) {
      page && (this.query.pageNum = page)
      this.loading = true
      api
        .getList(this.query)
        .then(({ rows, total, lastSyncTime }) => {
          console.log('群组投诉列表 = ', rows)
          this.list = rows
          console.log('this.list = ', this.list)
          this.total = +total
          this.lastSyncTime = lastSyncTime
          this.loading = false
        })
        .catch(() => {
          console.log('群组投诉列表失败 = ')
          this.loading = false
        })
    },
    edit(data, type) {
      this.form = JSON.parse(JSON.stringify(Object.assign({ groupTagType: this.type, weTags: [] }, data || {})))
      this.dialogVisible = true
      console.log(this.dialogVisible)
    },
    forbid(row) {
      this.form = JSON.parse(JSON.stringify(Object.assign({ id: row.id, beComplainGroupId: row.beComplainGroupId, status: '1' }, row || {})))
      this.dialogVisible = true
      console.log(this.dialogVisible)
    },
    unForbid(row, tips) {
      this.$confirm(tips, '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      })
        .then(() => {
          this.form = JSON.parse(JSON.stringify(Object.assign( row || {})))
          this.form.status = '2'
          this.loading = false
          api.handleComplian(this.form).then(() => {
                this.loading = false
                this.getList()
                this.msgSuccess('操作成功')
              }).catch(() => {
                this.loading = false
                this.msgError(`解除封禁失败`)
            })
        })
        .then(() => {
          
        })
      
    },

    syncTag() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
      })
      api
        .syncTag()
        .then(() => {
          loading.close()
          this.msgSuccess('后台开始同步数据，请稍后关注进度')
          this.getList()
        })
        .catch(() => {
          loading.close()
        })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.groupId)
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    remove(id) {
      const operIds = id || this.ids + ''
      this.$confirm('是否确认删除吗?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      })
        .then(function () {
          return api.remove(operIds)
        })
        .then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
    },
    handleComplain(res) {
      console.log('点击= ', res)
    }
  },
}
</script>
<template>
  <div class="">
    <el-form :model="query" :inline="true" label-width="0" label-position="left" class="top-search">
      <!-- <el-form-item label="">
        <el-input v-model="query.groupName" placeholder="请输入标签组名称" clearable @keyup.enter="getList(1)" />
      </el-form-item> -->
      <el-form-item label="" prop="status">
        <el-select :popper-append-to-body="false" v-model="query.status" placeholder="请选择当前状态">
          <el-option v-for="(item, index) in dictCustomerType" :key="index" :label="item" :value="index"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="0">
        <el-button type="primary" @click="getList(1)">查询</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="g-card">
      <div class="mid-action" style="display: none;">
        <div>
          <!-- v-hasPermi="['customerManage:tag:add']" -->
          <el-button type="primary" class="mr10" @click="edit()">新建标签组</el-button>
          <ButtonSync v-if="type == 1" :lastSyncTime="lastSyncTime" @click="syncTag">同步企微标签weizhi</ButtonSync>
        </div>
        <div>
          <!-- v-hasPermi="['customerManage:tag:remove']" -->
          <el-button :disabled="!ids.length" type="danger" @click="remove()">批量删除</el-button>
        </div>
      </div>
      <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="举报人" align="center" prop="nickName" />
        <el-table-column label="群组名称" align="center" prop="beComplainGroupName" />
        <el-table-column label="投诉类型" align="center" prop="complainTypeName" />
        <el-table-column label="投诉理由" align="center" prop="content" />
        <el-table-column label="投诉图片" align="center" prop="complainFiles">
          <template #default="{ row }">
            <!-- {{fileList}} -->
            <el-popover placement="bottom" trigger="hover">
              <template #reference>
                <!-- {{row.fileList[0].timPath}} -->
                <el-image v-if="row.complainFiles.length > 0" :src="row.complainFiles[0].timPath" class="code-image--small"></el-image>
              </template>
              <el-carousel :interval="5000" arrow="always" class="el-car">
                <el-carousel-item v-for="item in row.complainFiles" :key="item">
                  <!-- <el-image :src="row.timPath" class="code-image"></el-image> -->
                  <el-image :src="item.timPath" class="code-image"></el-image>
                </el-carousel-item>
              </el-carousel>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="封禁原因" align="center" prop="reason" >
          <template #default="{ row }">
            <div v-if="row.status == 0" text >---</div>
            <div v-if="row.status == 1" text>{{row.reason}}</div>
            <div v-if="row.status == 2" text>---</div>
          </template>
        </el-table-column>
        <el-table-column label="封禁结束时间" align="center" prop="expireTime" >
          <template #default="{ row }">
            <div v-if="row.status == 0" text >---</div>
            <div v-if="row.status == 1" text>{{row.expireTime}}</div>
            <div v-if="row.status == 2" text>---</div>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" />
        <!-- <el-table-column label="创建人" align="center" prop="createBy" /> -->
        <!-- <el-table-column label="创建时间" align="center" prop="operTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.operTime) }}</span>
        </template>
      </el-table-column>-->
      <!-- 0-审核中 1-被封禁 2-正常 -->
        <el-table-column label="状态" align="center" prop="gourpName" >
          <template #default="{ row }">
            <div v-if="row.status == 0" text >审核中</div>
            <div v-if="row.status == 1" text class="copy-btn">被封禁</div>
            <div v-if="row.status == 2" text >正常</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template #default="scope">
            <!-- v-hasPermi="['customerManage:tag:edit']" -->
            <el-button text v-if="scope.row.status == 0" @click="unForbid(scope.row, '确定忽略吗?')">忽略</el-button>
            <el-button text v-if="scope.row.status == 0" @click="forbid(scope.row)">封禁</el-button>
            <el-button text v-if="scope.row.status == 2" @click="remove(scope.row.groupId)">---</el-button>
            <el-button text v-if="scope.row.status == 1" @click="unForbid(scope.row, '确定解除封禁吗?')">解除封禁</el-button>
            <!-- v-hasPermi="['customerManage:tag:remove']" -->
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="query.pageNum"
        v-model:limit="query.pageSize"
        @pagination="getList()" />
    </div>

    <!-- 弹窗 -->
    <!-- <AddTag v-model:visible="dialogVisible" :form="form" :key="dialogVisible" @success="getList(!form.groupId && 1)" /> -->
    <AddTag v-model:visible="dialogVisible" :form="form" :key="dialogVisible" @success="getList()" />
  </div>
</template>
<style lang="scss" scoped>
.code-image {
  width: 360px;
  height: 360px;
}
.code-image--small {
  width: 50px;
  height: 50px;
}


.el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
  }
  
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }

  .el-car {
    width: 360px;
    height: 360px;
  }
  .copy-btn {
    color: #ff0000;
  }
</style>
